﻿using System;
using System.Web;
using System.Collections.Specialized;
using Eagle.Common;

namespace Eagle.Web
{
    /// <summary>
    /// 接受参数扩展类
    /// </summary>
    public class EagleRequest
    {
        #region 最底层参数接受，不对外使用
        /// <summary>
        /// 从地址栏接受参数，作为最底层方法，不对外使用
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string QueryString(string key)
        {
            if (key == null || key.Trim().Length == 0)
                throw new ArgumentNullException("key", "参数名称不能为空");
            string value = HttpContext.Current.Request.QueryString[key];
            if (value == null)
                return string.Empty;
            return value;
        }
        /// <summary>
        /// 从表单接受参数，作为最底层方法，不对外使用
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string FormString(string key)
        {
            if (key == null || key.Trim().Length == 0)
                throw new ArgumentNullException("key", "参数名称不能为空");
            string value = HttpContext.Current.Request.Form[key];
            if (value == null)
                return string.Empty;
            return value;
        }
        #endregion

        #region 从地址栏接受参数

        #region 转换为String

        /// <summary>
        /// 地址栏接受值，转换为String
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static String QueryToString(string key, String defaultValue)
        {
            return EagleUtils.UrlDecode(QueryString(key));
        }

        #endregion

        #region 转换为Int32

        /// <summary>
        /// 地址栏接受值，转换为Int32
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int32 QueryToInt32(string key, Int32 defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToInt32(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Int32
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int32? QueryToInt32(string key, Int32? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToInt32(value, defaultValue);
        }
        #endregion

        #region 转换为Int16

        /// <summary>
        /// 地址栏接受值，转换为Int16
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int16 QueryToInt16(string key, Int16 defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToInt16(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Int16
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int16? QueryToInt16(string key, Int16? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToInt16(value, defaultValue);
        }
        #endregion

        #region 转换为Int64

        /// <summary>
        /// 地址栏接受值，转换为Int64
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int64 QueryToInt64(string key, Int64 defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToInt64(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Int64
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int64? QueryToInt64(string key, Int64? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToInt64(value, defaultValue);
        }
        #endregion

        #region 转换为byte

        /// <summary>
        /// 地址栏接受值，转换为byte
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static byte QueryToByte(string key, byte defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToByte(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为byte
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static byte? QueryToByte(string key, byte? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToByte(value, defaultValue);
        }
        #endregion

        #region 转换为bool

        /// <summary>
        /// 地址栏接受值，转换为bool
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static bool QueryToBoolean(string key, bool defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToBoolean(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为bool
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static bool? QueryToBoolean(string key, bool? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToBoolean(value, defaultValue);
        }
        #endregion

        #region 转换为UInt32

        /// <summary>
        /// 地址栏接受值，转换为UInt32
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt32 QueryToUInt32(string key, UInt32 defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToUInt32(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为UInt32
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt32? QueryToUInt32(string key, UInt32? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToUInt32(value, defaultValue);
        }
        #endregion

        #region 转换为UInt16

        /// <summary>
        /// 地址栏接受值，转换为Int16
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt16 QueryToUInt16(string key, UInt16 defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToUInt16(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Int16
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt16? QueryToUInt16(string key, UInt16? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToUInt16(value, defaultValue);
        }
        #endregion

        #region 转换为UInt64

        /// <summary>
        /// 地址栏接受值，转换为UInt64
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt64 QueryToUInt64(string key, UInt64 defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToUInt64(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为UInt64
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt64? QueryToUInt64(string key, UInt64? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToUInt64(value, defaultValue);
        }
        #endregion

        #region 转换为SByte

        /// <summary>
        /// 地址栏接受值，转换为SByte
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static SByte QueryToSByte(string key, SByte defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToSByte(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为SByte
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static SByte? QueryToSByte(string key, SByte? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToSByte(value, defaultValue);
        }
        #endregion

        #region 转换为Decimal

        /// <summary>
        /// 地址栏接受值，转换为Decimal
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Decimal QueryToDecimal(string key, Decimal defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToDecimal(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Decimal
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Decimal? QueryToDecimal(string key, Decimal? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToDecimal(value, defaultValue);
        }
        #endregion

        #region 转换为DateTime

        /// <summary>
        /// 地址栏接受值，转换为Decimal
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static DateTime QueryToDateTime(string key, DateTime defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToDateTime(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Decimal
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static DateTime? QueryToDateTime(string key, DateTime? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToDateTime(value, defaultValue);
        }
        #endregion

        #region 转换为Single

        /// <summary>
        /// 地址栏接受值，转换为Single
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Single QueryToSingle(string key, Single defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToSingle(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Single
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Single? QueryToSingle(string key, Single? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToSingle(value, defaultValue);
        }
        #endregion

        #region 转换为Double

        /// <summary>
        /// 地址栏接受值，转换为Double
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Double QueryToDouble(string key, Double defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToDouble(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Double
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Double? QueryToDouble(string key, Double? defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToDouble(value, defaultValue);
        }
        #endregion

        #region 转换为Guid

        /// <summary>
        /// 地址栏接受值，转换为Guid
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Guid QueryToGuid(string key, Guid defaultValue)
        {
            string value = QueryString(key);
            return DataConvert.ToGuid(value, defaultValue);
        }

        #endregion

        #endregion

        #region 从表单接受参数

        #region 转换为String

        /// <summary>
        /// 表单接受值，转换为String
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static String FormToString(string key, String defaultValue)
        {
            return EagleUtils.UrlDecode(FormString(key));
        }

        #endregion

        #region 转换为Int32

        /// <summary>
        /// 表单接受值，转换为Int32
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int32 FormToInt32(string key, Int32 defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToInt32(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为Int32
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int32? FormToInt32(string key, Int32? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToInt32(value, defaultValue);
        }
        #endregion

        #region 转换为Int16

        /// <summary>
        /// 表单接受值，转换为Int16
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int16 FormToInt16(string key, Int16 defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToInt16(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为Int16
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int16? FormToInt16(string key, Int16? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToInt16(value, defaultValue);
        }
        #endregion

        #region 转换为Int64

        /// <summary>
        /// 表单接受值，转换为Int64
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int64 FormToInt64(string key, Int64 defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToInt64(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为Int64
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Int64? FormToInt64(string key, Int64? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToInt64(value, defaultValue);
        }
        #endregion

        #region 转换为byte

        /// <summary>
        /// 表单接受值，转换为byte
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static byte FormToByte(string key, byte defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToByte(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为byte
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static byte? FormToByte(string key, byte? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToByte(value, defaultValue);
        }
        #endregion

        #region 转换为UInt32

        /// <summary>
        /// 地址栏接受值，转换为UInt32
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt32 FormToUInt32(string key, UInt32 defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToUInt32(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为UInt32
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt32? FormToUInt32(string key, UInt32? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToUInt32(value, defaultValue);
        }
        #endregion

        #region 转换为UInt16

        /// <summary>
        /// 地址栏接受值，转换为Int16
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt16 FormToUInt16(string key, UInt16 defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToUInt16(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为Int16
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt16? FormToUInt16(string key, UInt16? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToUInt16(value, defaultValue);
        }
        #endregion

        #region 转换为UInt64

        /// <summary>
        /// 地址栏接受值，转换为UInt64
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt64 FormToUInt64(string key, UInt64 defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToUInt64(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为UInt64
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static UInt64? FormToUInt64(string key, UInt64? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToUInt64(value, defaultValue);
        }
        #endregion

        #region 转换为SByte

        /// <summary>
        /// 地址栏接受值，转换为SByte
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static SByte FormToSByte(string key, SByte defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToSByte(value, defaultValue);
        }
        /// <summary>
        /// 地址栏接受值，转换为SByte
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static SByte? FormToSByte(string key, SByte? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToSByte(value, defaultValue);
        }
        #endregion

        #region 转换为bool

        /// <summary>
        /// 表单接受值，转换为bool
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static bool FormToBoolean(string key, bool defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToBoolean(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为bool
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static bool? FormToBoolean(string key, bool? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToBoolean(value, defaultValue);
        }
        #endregion

        #region 转换为Decimal

        /// <summary>
        /// 表单接受值，转换为Decimal
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Decimal FormToDecimal(string key, Decimal defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToDecimal(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为Decimal
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Decimal? FormToDecimal(string key, Decimal? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToDecimal(value, defaultValue);
        }
        #endregion

        #region 转换为DateTime

        /// <summary>
        /// 表单接受值，转换为Decimal
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static DateTime FormToDateTime(string key, DateTime defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToDateTime(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为Decimal
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static DateTime? FormToDateTime(string key, DateTime? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToDateTime(value, defaultValue);
        }
        #endregion

        #region 转换为Single

        /// <summary>
        /// 表单接受值，转换为Single
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Single FormToSingle(string key, Single defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToSingle(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为Single
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Single? FormToSingle(string key, Single? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToSingle(value, defaultValue);
        }
        #endregion

        #region 转换为Double

        /// <summary>
        /// 表单接受值，转换为Double
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Double FormToDouble(string key, Double defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToDouble(value, defaultValue);
        }
        /// <summary>
        /// 表单接受值，转换为Double
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Double? FormToDouble(string key, Double? defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToDouble(value, defaultValue);
        }
        #endregion

        #region 转换为Guid

        /// <summary>
        /// 表单接受值，转换为Guid
        /// </summary>
        /// <param name="key">参数名</param>
        /// <param name="defaultValue">转换不成功时返回默认值</param>
        /// <returns></returns>
        public static Guid FormToGuid(string key, Guid defaultValue)
        {
            string value = FormString(key);
            return DataConvert.ToGuid(value, defaultValue);
        }

        #endregion

        #endregion

        #region 富文本内容过滤函数，这里只提供从表单(post)传值，因为大内容都会从表单(post)传值
        /// <summary>
        /// 富文本内容过滤函数，只接受从表单提交的传值，返回过滤后的字符串,如果字符串为空，返回string.Empty
        /// </summary>
        /// <param name="key">参数名称</param>
        /// <returns></returns>
        [Obsolete("请使用FormToString方法，如果要编码危险字符，使用HttpUtility.HtmlEncode")]
        public static string BodyEncode(string key)
        {
            return BodyEncode(key, string.Empty);
        }
        /// <summary>
        /// 富文本内容过滤函数，只接受从表单提交的传值，返回过滤后的字符串,如果字符串为空，返回string.Empty
        /// </summary>
        /// <param name="key">参数名称</param>
        /// <param name="defaultValue">为空时返回的默认值</param>
        /// <returns></returns>
         [Obsolete("请使用FormToString方法，如果要编码危险字符，使用HttpUtility.HtmlEncode")]
        public static string BodyEncode(string key, string defaultValue)
        {
            string value = EagleUtils.UrlDecode(FormString(key));
            if (value.Length == 0)
                return defaultValue;
            return value;
        }
        /// <summary>
        /// 只接受从表单的传值，传入参数名称即可，返回过滤后的字符串,如果字符串为空，返回string.Empty
        /// </summary>
        /// <param name="key">参数名称</param>
        /// <param name="count">要截取的字符串长度</param>
        /// <param name="cuttype">截取类型</param>
        /// <returns></returns>
         [Obsolete("请使用FormToString方法，如果要编码危险字符，使用HttpUtility.HtmlEncode")]
        public static string BodyEncode(string key, int length, EagleUtils.CutType cuttype)
        {
            string value = BodyEncode(key, string.Empty);
            value = EagleUtils.CutString(value, length, false, cuttype);
            return value;
        }
        #endregion
    }
}
